package com.niiwoo.civet.trade.dao.mapper;

import com.niiwoo.civet.trade.dao.entity.ProjectInvesting;
import com.niiwoo.civet.trade.dto.request.NoviceInvestListRequestDTO;
import com.niiwoo.civet.trade.dto.request.myloan.InvestingProjectPageRequestDTO;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public interface ProjectInvestingMapperExt extends ProjectInvestingMapper {

    List<ProjectInvesting> selectListByProjectIdSet(List<Long> list);

    ProjectInvesting selectListGroupByDeadLine(@Param("deadline") Integer deadline,@Param("channelCode") String channelCode);

    List<ProjectInvesting> selectPageByParams(@Param("params") InvestingProjectPageRequestDTO investingProjectPageRequestDTO);

	Integer selectPageByParamsCount(@Param("params") InvestingProjectPageRequestDTO investingProjectPageRequestDTO);

    List<ProjectInvesting> selectSoldOutList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize,@Param("type")Byte type);

	List<ProjectInvesting> selectRecommendListByParams(@Param("channelCode") String channelCode,
	                                                   @Param("projectType") Byte projectType,
	                                                   @Param("borrowRate") BigDecimal borrowRate,
	                                                   @Param("deadline") Integer deadline,
	                                                   @Param("deadlineUnit") Byte deadlineUnit);

    List<ProjectInvesting> selectAllWithLimit(@Param("limit") int limit);

    /**
     *
     * @param deadUnit
     * @param deadLine
     * @param status
     * @param orgId
     * @param sortOrder
     * @return
     */
    ProjectInvesting selectByDeadlineAndStatus(@Param("deadUnit")Byte deadUnit,
                                               @Param("deadLine")Integer deadLine,
                                               @Param("status") Byte status,
                                               @Param("orgId") String orgId,
                                               @Param("sortOrder") Byte sortOrder,
											   @Param("repaymentType") Byte repaymentType,
											   @Param("channelCode") String channelCode);

    List<ProjectInvesting> selectFanLiInvestPageByParams(@Param("offset") Integer offset, @Param("pageSize")Integer pageSize, @Param("channelCode") String channelCode);

    int accountFanLiInvestPageByParams(@Param("channelCode") String channelCode);

    /**
     * 查询目前可投标的数量
     * @return
     */
    int selectInvestableProjectCount(@Param("loanTypeList")List<Byte> loanTypeList);


	 /**
     * 批量投资匹配标
     * @param userId
     * @param productTypes
     * @param ratetTypes
     * @param repaymentTypes
     * @return
     */
	List<ProjectInvesting> queryAllInvestingProjectWithCondition(@Param("userId")String userId,@Param("productTypes") List<Integer> productTypes,@Param("repaymentTypes") List<Integer> repaymentTypes);
	/**
	 * 查询指定时间之前的可以投资标
	 * @param date
	 * @return
	 */
	List<ProjectInvesting> selectAllWithPublicTime(Date date);


    /**
     * 重置标的加息
     * 
     * @param projectId
     * @return
     */
	int resetProjectRaiseRate(Long projectId);

	/**
	 * 查询新手标列表，必传channel——code分端发标
	 * 无筛选无排序，根据期限分组，满标后则换一条
	 * @param requestDTO
	 * @return
	 */
    List<ProjectInvesting> selectNoviceInvestPage(@Param("params") NoviceInvestListRequestDTO requestDTO);

	/**
	 * 查询新手标条数
	 * @param requestDTO
	 * @return
	 */
	Integer selectNoviceInvestPageCount(@Param("params") NoviceInvestListRequestDTO requestDTO);
	/**
	 * 查询可以投资的标
	 * @param projectIds
	 * @return
	 */
	List<ProjectInvesting> selectCanInvestByProjectIds(@Param("projectIds")List<Long> projectIds,@Param("userId")String userId);

	int resetInvestEndTime(@Param("projectId")Long projectId);

	/**
	 * 根据分端编码查询最近一条投资中记录
	 * @param channelCode
	 * @return
     */
	ProjectInvesting selectLastOneByChannelCode(@Param("channelCode") String channelCode);

	/**
	 * 利率分组
	 * @return
	 */
	HashMap<String,BigDecimal> selectProjectInvestingListByRate();

	/**
	 * 期限分组
	 * @return
	 */
	List<HashMap<String,Object>> selectProjectInvestingListByDeadLine();
}